<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Class Msetting extends MY_Model
{
    public function __construct()
    {
        parent::__construct();
    }
    
    
    public function getLimitUserCC()
    {
        $data = $this->db->query('SELECT content, action FROM setting WHERE `action` in ("limitcoupon", "limitcode") ORDER BY id DESC')->result_object();
        $arr = array();
        foreach($data AS $el=>$le)
        {
            $exp = null;
            $exp = explode(',', $le->content);
            if($le->action == 'limitcoupon')
            {
                $arr['form_coupon'] = $exp[0];
                $arr['to_coupon'] = $exp[1];
            }else  if($le->action == 'limitcode')
            {
                $arr['form_code'] = $exp[0];
                $arr['to_code'] = $exp[1];
            }
        }
        return (object)$arr;
    }
    
    public function updateLimitUserCC()
    {
        $this->db->update('setting', array('content' => $this->getParamInt('form_coupon').','. $this->getParamInt('to_coupon')), "action = 'limitcoupon'");
        $this->db->update('setting', array('content' => $this->getParamInt('form_code').','. $this->getParamInt('to_code')), "action = 'limitcode'");
        return 200;
    }

}
